package com.scpii.universal.util;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;

import com.scpii.universal.dispatch.Const.DispathConfig;

/**
 * 修改内容：将原来的INI文件替换为properties文件！ 加载dispatch.properties配制文件 修改时间：2012-12-18
 * 修改人：左柳波
 */
public class DispathConfigUtil {

	private static final Logger logger = LoggerFactory
			.getLogger(DispathConfigUtil.class);

	public static void load(String location) throws FileNotFoundException,
			IOException {
		ResourceLoader resourceLoader = new DefaultResourceLoader();
		Resource resource = resourceLoader.getResource(location);
		InputStream inputStream = resource.getInputStream();
		Properties p = new Properties();

		try {
			p.load(inputStream);
			// 取Properties文件的数据，并存放在对应的类里面
			DispathConfig.PACK_TASK_POOL_NUM = p
					.getProperty("PACK_TASK_POOL_NUM");
			DispathConfig.DOWNLOAD_PIC_TASK_POOL_NUM = p
					.getProperty("DOWNLOAD_PIC_TASK_POOL_NUM");
			DispathConfig.PACK_TASK_POOL_AWAIT_TIME = p
					.getProperty("PACK_TASK_POOL_AWAIT_TIME");
			DispathConfig.DOWNLOADPIC_TASK_POOL_AWAIT_TIME = p
					.getProperty("DOWNLOADPIC_TASK_POOL_AWAIT_TIME");
			DispathConfig.SERVER_HOST_API = p.getProperty("SERVER_HOST_API");
			/**
			 * 修改内容：新增PUSH接口地址 修改人：左柳波 修改时间：2012-12-20
			 */
			DispathConfig.SERVER_PUSH_API = p.getProperty("SERVER_PUSH_API");
			DispathConfig.API = p.getProperty("API");
			DispathConfig.APP_SECRET = p.getProperty("APP_SECRET");

			DispathConfig.SERVER_HOST = p.getProperty("SERVER_HOST");
			DispathConfig.UNIVERSAL_DISPATCH_TEMP_DIR = p
					.getProperty("UNIVERSAL_DISPATCH_TEMP_DIR");
			DispathConfig.UNIVERSAL_DISPATCH_CONFIG_DIR = p
					.getProperty("UNIVERSAL_DISPATCH_CONFIG_DIR");
			DispathConfig.UNIVERSAL_DISPATCH_STORE_DIR = p
					.getProperty("UNIVERSAL_DISPATCH_STORE_DIR");
			DispathConfig.UNIVERSAL_DISPATCH_DIR = p
					.getProperty("UNIVERSAL_DISPATCH_DIR");
			DispathConfig.ZIP_SUB_CONFIG = p.getProperty("ZIP_SUB_CONFIG");
			DispathConfig.ZIP_SUB_RESOURCE = p.getProperty("ZIP_SUB_RESOURCE");
			DispathConfig.ZIP_SUB_CERTIFICATION = p
					.getProperty("ZIP_SUB_CERTIFICATION");
			DispathConfig.CONFIG_INI = p.getProperty("CONFIG_INI");
			DispathConfig.IOS_APP_OS_TYPE = p.getProperty("IOS_APP_OS_TYPE");
			DispathConfig.ANDROID_APP_OS_TYPE = p
					.getProperty("ANDROID_APP_OS_TYPE");
			DispathConfig.FTP_HOST = p.getProperty("FTP_HOST");
			DispathConfig.FTP_STORE_DIR = p.getProperty("FTP_STORE_DIR");
			DispathConfig.GOOGLE_ANALYTICS = p.getProperty("GOOGLE_ANALYTICS");
			DispathConfig.REGISTER_ALLOW_KEY = p
					.getProperty("REGISTER_ALLOW_KEY");
			DispathConfig.DEFAULT_SINA_APP_KEY = p
					.getProperty("DEFAULT_SINA_APP_KEY");
			DispathConfig.DEFAULT_SINA_APP_ID = p
					.getProperty("DEFAULT_SINA_APP_ID");
			DispathConfig.DEFAULT_WX_APP_KEY = p
					.getProperty("DEFAULT_WX_APP_KEY");
			DispathConfig.DEFAULT_WX_APP_ID = p
					.getProperty("DEFAULT_WX_APP_ID");
			DispathConfig.DEFAULT_TENCENT_APP_KEY = p
					.getProperty("DEFAULT_TENCENT_APP_KEY");
			DispathConfig.DEFAULT_TENCENT_APP_ID = p
					.getProperty("DEFAULT_TENCENT_APP_ID");
			DispathConfig.ENVIRONMENT = p.getProperty("ENVIRONMENT");

		} catch (IOException e) {
			logger.error("加载配置文件" + location + "失败");
		} finally {
			try {
				if (inputStream != null)
					inputStream.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

}
